package com.paradox.aggregation.consumer.service;

import com.paradox.aggregation.consumer.entity.Providers;
import com.paradox.aggregation.consumer.mapper.ProvidersMapper;
import com.paradox.aggregation.providerAPI.api.ProviderService;
import io.seata.core.context.RootContext;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ConsumerService {

    @Autowired
    private ProviderService providerService;
    @Autowired
    private ProvidersMapper providersMapper;

    @GlobalTransactional(name="naxx")
    public Object getProviders(){
        String xid= RootContext.getXID();
        System.out.println("xid:"+xid);
        providersMapper.insert(new Providers("xixixi","dfdf",new Date()));
        Boolean res=providerService.testMysql();
        System.out.println("test reslut:"+res);
        if(!res) throw new RuntimeException("服务异常降级了");
        return "null";
    }
}
